package com.kly.smartbi.test.day4;

import lombok.extern.slf4j.Slf4j;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

/**
 * @author admin
 * @date 2025/4/5
 */
@Slf4j
public class Demo1 {
    public static void main(String[] args) {
        reverseWords("  it is   a word  1");
    }


    /**
     * 求和
     */
    public void getSum() {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        int n = scan.nextInt();
        long[] arr = new long[n];
        long sum  = 0;
        for(int i = 0; i < n; i++) {
            arr[i] = scan.nextLong();
            sum += arr[i];
        }

        long res = 0;
        for(int i = 0; i < n; i++) {
            sum -= arr[i];
            res = sum * arr[i];
        }

        System.out.println(res);
        scan.close();
    }


    /**
     * 反转字符串中的单词
     */
    public static void reverseWords(String str) {
    //     1. 清除多余空格
        char[] charArray = str.toCharArray();
        charArray = clearExtraSpaces(charArray);
        //     2. 反转字符串
        reverseString(charArray, 0, charArray.length - 1);
    //     3. 反转单词
        reverseWord(charArray);
        System.out.println(String.valueOf(charArray));
    }

    /**
     * 反转单词
     */
    public static void reverseWord(char[] charArray) {
        int start = 0;
        for(int end = 0; end <= charArray.length; end++) {
            if(end == charArray.length || charArray[end] == ' ') {
                reverseString(charArray, start, end - 1);
                start = end + 1;
            }
        }
    }
    /**
     * 反转字符串 2
     */
    public static void reverseString(char[] charArray, int start, int end) {
        while(start < end) {
            char temp = charArray[start];
            charArray[start] = charArray[end];
            charArray[end] = temp;
            start++;
            end--;
        }
    }

    /**
     * 清除多余空格
     */
    public static char[] clearExtraSpaces(char[] charArray) {
        int slow = 0;
        for(int j = 0; j < charArray.length; j++) {
            if(charArray[j] != ' ') {
                if(slow != 0) charArray[slow++] = ' ';
                while(j < charArray.length && charArray[j] != ' ') {
                    charArray[slow++] = charArray[j++];
                }
            }
        }
        char[] newCharArray = new char[slow];
        System.arraycopy(charArray, 0, newCharArray, 0, slow);
        return newCharArray;
    }


    /**
     *  填充数字
     */
    public static void fillNumber() {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        String str = scan.next();
        char[] charArray = str.toCharArray();
    //     统计数字个数
        int numCount = 0;
        for (char c : charArray) {
            if (Character.isDigit(c)) {
                numCount++;
            }
        }
    //     对数组扩容
        char[] newCharArray = new char[charArray.length + numCount * 5];
        // 拷贝数组
        System.arraycopy(charArray, 0, newCharArray, 0, charArray.length);
        int len = charArray.length - 1;
        for(int i = newCharArray.length - 1, j = len; i > len; i--, j--) {
            if(!Character.isDigit(newCharArray[j])) {
                newCharArray[i] = newCharArray[j];
            } else {
                // number
                newCharArray[i] = 'r';
                newCharArray[i - 1] = 'e';
                newCharArray[i - 2] = 'b';
                newCharArray[i - 3] = 'm';
                newCharArray[i - 4] = 'u';
                newCharArray[i - 5] = 'n';
                i -= 5;
            }
        }
        System.out.println(String.valueOf(newCharArray));
    }

    /**
     * 反转字符串
     */
    public static void reverseString(String str) {
        char[] charArray = str.toCharArray();
        int l = 0;
        int r = charArray.length - 1;
        while(l < r) {
            char temp = charArray[l];
            charArray[l] = charArray[r];
            charArray[r] = temp;
            l++;
            r--;
        }
    }


    /**
     * 特别的数之和
     */
    public static void getSpecialNumberSum() {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        int num = scan.nextInt();
        int sum = 0;
        for(int i = 1; i <= num; i++) {
            if(isNum(i)) {
                sum += i;
            }
        }
        System.out.println(sum);

        scan.close();
    }

    public static boolean isNum(int num) {
        while(num > 0) {
            int n = num % 10;
            if(n == 2 || n == 0 || n == 1 || n == 9) {
                return true;
            }
            num /= 10;
        }
        return false;
    }

    /**
     * 计算当前时间 通过毫秒值
     */
    public static void getCurrentTime() {
        long currentTimeMillis = System.currentTimeMillis();
        Date date = new Date(currentTimeMillis);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm:ss");
        String format = simpleDateFormat.format(date);
        System.out.println(format);
    }

    /**
     * 刷题统计
     */
    public static void getPassRate() {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        int a = scan.nextInt();
        int b = scan.nextInt();
        int n = scan.nextInt();

        int sum = 0;
        int day = 0;

        while(sum < n) {
            day++;
            if(day % 7 == 6 || day % 7 == 0) {
                sum += b;
            } else {
                sum += a;
            }
        }
        System.out.println(day);

        scan.close();
    }

}
